import { Setting } from 'obsidian'
import type Emo from '../main'
import { EmoFragment } from '../base/emo-fragment'
import { HostingProvider } from '../config'
import { t } from '../lang/helpers'
import type { GiteeParms } from '../parms/parms-gitee'

export class GiteeFragment extends EmoFragment {
  constructor (el: HTMLElement, plugin: Emo) {
    super(HostingProvider.GITEE, el, plugin)
  }

  display (el: HTMLElement, plugin: Emo): void {
    const parms = plugin.config.GITEE_parms
    el.createEl('h3', { text: 'Gitee Settings' })

    new Setting(el)
      .setName(t('owner'))
      .addText((text) => {
        text
          .setValue(parms.required.owner)
          .onChange(async (value) => {
            parms.required.owner = value
            await plugin.saveSettings()
          })
      })

    new Setting(el)
      .setName(t('repo'))
      .addText((text) => {
        text
          .setValue(parms.required.repo)
          .onChange(async (value) => {
            parms.required.repo = value
            await plugin.saveSettings()
          })
      })

    new Setting(el)
      .setName(t('branch'))
      .addText((text) => {
        text
          .setValue(parms.required.branch)
          .onChange(async (value) => {
            parms.required.branch = value
            await plugin.saveSettings()
          })
      })

    new Setting(el)
      .setName('access_token')
      .addText((text) => {
        text
          .setValue(parms.required.access_token)
          .onChange(async (value) => {
            parms.required.access_token = value
            await plugin.saveSettings()
          })
      })

    new Setting(el)
      .setName(t('path'))
      .addText((text) => {
        text
          .setValue(parms.path)
          .onChange(async (value) => {
            parms.path = value
            await plugin.saveSettings()
          })
      })

    new Setting(el)
      .setName(t('random filename'))
      .addToggle((toggle) => {
        toggle
          .setValue(parms.random)
          .onChange(async (value) => {
            parms.random = value
            await plugin.saveSettings()
          })
      })
  }
}